<?php
namespace Fwadmin\Controller;
use Think\Controller;
class ArticleController extends BaseController{
	public function index(){
		$category_id	= I('category_id');
		$categoryInfo	= M('Category') -> where(array('id' => $category_id)) -> find();
		if($_GET['p']==''){
			$_GET['p'] = 1;
		}
		$category		= getCategory($category_id);
		$map['category_id'] = $category_id;
		$post_start_time		= str_replace('+',' ',trim(I('start_time')));
		$post_end_time			= str_replace('+',' ',trim(I('end_time')));
		$post_keyword			= trim(I('keyword'));
		$post_status			= trim(I('status'));
		if($post_start_time != '' && $post_end_time != ''){
			$map['add_time'] = array(array('EGT',$post_start_time),array('ELT',$post_end_time));
		}
		if($post_keyword != ''){
			$map['title'] = array('LIKE', '%'.$post_keyword.'%');
		}
		$map['status'] = array('EQ', $post_status);
		$viewList	= M('Article') -> where($map) -> order('id desc') -> page($_GET['p'].',15') -> select();
		$count		= M('Article') -> where($map) -> count();
		$Pages		= new \Think\Page($count, 15); 
		$Page		-> url = 'page';
		$show		= $Pages -> show();

		$this		-> assign('post_start_time',$post_start_time);
		$this		-> assign('post_end_time',$post_end_time);
		$this		-> assign('post_keyword',$post_keyword);
		$this		-> assign('post_status',$post_status);
		$this		-> assign('category_id',$category_id);
		$this		-> assign('category',$category);
		$this		-> assign('categoryInfo',$categoryInfo);
		$this		-> assign('viewList',$viewList);
		$this		-> assign('pages',$show);
		$this		-> display();
	}
	public function add(){
		$category_id	= I('category_id');
		$category		= getCategory($category_id);
		$categoryInfo	= M('Category') -> where(array('id' => $category_id)) -> find();

		$this -> assign('category_id',$category_id);
		$this -> assign('category',$category);
		$this -> assign('categoryInfo',$categoryInfo);
		$this -> display('add');
	}
	public function edit(){
		$id				= I('id');
		$category_id	= I('category_id');
		$category		= getCategory($category_id);
		$categoryInfo	= M('Category') -> where(array('id' => $category_id)) -> find();
		$viewInfo		= M('Article') -> where(array('id' => $id)) -> find();
		$gallery		= M('Gallery') -> where(array('cid' => $viewInfo['cid'])) -> select();
		$this -> assign('category_id',$category_id);
		$this -> assign('category',$category);
		$this -> assign('categoryInfo',$categoryInfo);
		$this -> assign('viewInfo',$viewInfo);
		$this -> assign('gallery',$gallery);
		$this -> display('edit');
	}
}